package Presentation;

import BusinessLogic.Command;
import BusinessLogic.Sound;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.ImageIcon;

public class frmStateInfo extends javax.swing.JFrame {
    
    String username="";
    
    public frmStateInfo() {
        initComponents();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int width = (int) screenSize.getWidth() - 220;
        int height = (int) screenSize.getHeight() - 45;
        setLocation(width, height);
        this.setVisible(false);
        this.pack();
        setIcon();
    }
    
    private void setIcon() {
        setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/Images/icon.png")));
    }
    
    //Hiển thị thông báo trạng thái
    public void notice(String state, String friend){
        this.setTitle(username +" có thông báo");
        if(state.equals(Command.ONLINE)){
            lbl_Notice.setIcon(new ImageIcon(getClass().getResource("/Images/status_online.png")));
            lbl_Notice.setText(friend+ " vừa online");
            new Sound().play("online");
            showfrm();
            this.setVisible(false);
        }
        if(state.equals(Command.OFFLINE)){
            lbl_Notice.setIcon(new ImageIcon(getClass().getResource("/Images/status_offline.png")));
            lbl_Notice.setText(friend+ " đã offline");
            new Sound().play("offline");
            showfrm();
            this.setVisible(false);
        }
        if(state.equals(Command.BUSY)){
            lbl_Notice.setIcon(new ImageIcon(getClass().getResource("/Images/status_busy.png")));
            lbl_Notice.setText(friend+ " đang bận");
            new Sound().play("busy");
            showfrm();
            this.setVisible(false);
        }
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbl_Notice = new javax.swing.JLabel();

        setBackground(new java.awt.Color(204, 204, 255));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setResizable(false);
        setType(java.awt.Window.Type.UTILITY);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        lbl_Notice.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lbl_Notice.setForeground(new java.awt.Color(0, 51, 204));
        lbl_Notice.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lbl_Notice, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lbl_Notice, javax.swing.GroupLayout.DEFAULT_SIZE, 24, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened

    }//GEN-LAST:event_formWindowOpened
    
    private void showfrm(){
        try{ 
            for(int i = 0; i < 60; i++) { 
                Thread.sleep(3); 
                this.setLocation(this.getLocationOnScreen().x, this.getLocationOnScreen().y - 1); 
            }
            Thread.sleep(3000); 
            for(int i = 0; i < 60; i++) { 
                Thread.sleep(3); 
                this.setLocation(this.getLocationOnScreen().x, this.getLocationOnScreen().y + 1); 
            }      
        } 
        catch (InterruptedException e) { 
        }
    }
    
    public void setFriend(String str){
       lbl_Notice.setText(str);
    }
    
    public void setUsername(String str){
        this.setTitle(str);
        username=str;       
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel lbl_Notice;
    // End of variables declaration//GEN-END:variables
}
